package com.dahua.simplefactory.version4;

import java.util.Scanner;

/**
 * @author sunhongguang
 * @create 2022-01-09-12:07
 */
public class Client {

    public static void main(String[] args) {
        try {
            double numberA;
            double numberB;
            double result;
            Operation operation;

            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入操作数A： ");
            numberA = scanner.nextDouble();

            System.out.println("请选择运算符号（+、-、*、/、√、）: ");
            String operate = scanner.next();
            if(operate.equals("√")){
                operation = OperationFactory.createOperate(operate);
                operation.setNumberA(numberA);
                result = operation.getResult();
                System.out.println("结果是："+result);
                return;
            }else {
                System.out.println("请输入操作数B： ");
                numberB = scanner.nextDouble();
                operation = OperationFactory.createOperate(operate);
                operation.setNumberA(numberA);
                operation.setNumberB(numberB);
            }
            result = operation.getResult();
            System.out.println("结果是："+result);
        }catch (Exception e){
            System.out.println(e);
        }
    }
}
